//注册页面
const nameInp = document.querySelector('.couns > input')
const pwdInp = document.querySelector('.password > input')
const rpwdInp = document.querySelector('.rpassword > input')
const nickInp = document.querySelector('.nickname > input')
const errBox = document.querySelector('.error')
const form = document.querySelector('form')
form.addEventListener("submit", e =>{
    e = e || window.event

    e.preventDefault()

    const name = nameInp.value
    const pwd = pwdInp.value
    const rpwd = rpwdInp.value
    const nick = nickInp.value

    if(!name || !pwd || !rpwd || !nick )
    return alert('请认真完善信息')

    if(pwd !== rpwd){
        errBox.innerHTML = '两次密码输入不一致,请重新输入!!'
        errBox.getElementsByClassName.display = 'block'
        return
    }
    const data = `username=${name}&password=${pwd}&rpassword=${rpwd}&nickname=${nick}`
    ajax({
        url:'../server/register.php',
        data,
        method:'POST',
        dataType:'json',
        success(res){

            if(res.code === 0){
                errBox.innerHTML = '用户名已存在!!'
                errBox.getElementsByClassName.display = 'block'
                return

            }
            if(res.code === 1)
            alert('注册成功,点击确定跳转至登录页登录')
            window.location.href = './login.html'
        }
    })

})